import { BasicColumn } from '/@/components/Table';
import { FormSchema } from '/@/components/Table';
import { h } from 'vue';
import { Tag } from 'ant-design-vue';

import { uploadApi } from '/@/api/sys/upload';
import { getAllList } from '/@/api/privilege/account';

// 表格定义
export const columns: BasicColumn[] = [
  {
    title: '委托单位',
    dataIndex: 'contract.clientName',
    customRender: ({ record }) => {
      return record.contract ? record.contract.clientName : '';
    },
  },
  {
    title: '摘要',
    dataIndex: 'summary',
    customRender: ({ record }) => {
      return record.work ? record.work.summary : '';
    },
  },
  {
    title: '发起人',
    dataIndex: 'operatorName',
    customRender: ({ record }) => {
      if (record.work) {
        const color = 'green';
        const text = record.work.operatorName;
        return h(Tag, { color: color }, () => text)
      }
      return '';
    },
  },
  {
    title: '发起时间',
    dataIndex: 'work.startTime',
    customRender: ({ record }) => {
      return record.work ? record.work.startTime : '';
    },
  },
  {
    title: '完成时间',
    dataIndex: 'work.stopTime',
    customRender: ({ record }) => {
      return record.work ? record.work.stopTime : '';
    },
  },
  {
    title: '流程状态',
    dataIndex: 'statusName',
    customRender: ({ record }) => {
      if (record.work) {
        const color = record.work.status == 20 ? 'red' : 'green';
        const text = record.work.statusName;
        return h(Tag, { color: color }, () => text);
      }
      return ''
    },
  }
];

export const searchFormSchema: FormSchema[] = [
  {
    field: 'keyword',
    label: '关键字',
    component: 'Input',
    componentProps: {
      placeholder: '请输入名称/编码',
    },
    labelWidth: 60,
    colProps: { span: 6, lg: { span: 6, offset: 0 }, sm: { span: 10, offset: 0 }, xs: { span: 16, offset: 0 } },
  },
];

//新增表单
export const formSchema: FormSchema[] = [
  {
    field: 'id',
    label: 'ID',
    component: 'Input',
    show: false,
  },
  {
    field: 'contract.formNo',
    label: '合同编号',
    component: 'Input',
    componentProps: {
      disabled: true,
    },
  },
  {
    field: 'contract.clientName',
    label: '委托单位',
    component: 'Input',
    componentProps: {
      disabled: true,
    },
  },
  {
    field: 'itemName',
    label: '委托业务',
    component: 'Input',
    componentProps: {
      disabled: true,
    },
  },
  {
    field: 'contract.clientManager',
    label: '联系人及电话',
    component: 'Input',
    componentProps: {
      disabled: true,
    },
  },
  {
    field: 'contract.clientAddress',
    label: '地址',
    component: 'Input',
    componentProps: {
      disabled: true,
    },
  },
  {
    field: 'contract.finishTime',
    label: '计划完成日期',
    component: 'Input',
    componentProps: {
      disabled: true,
    },
  },
  {
    field: 'extInfoList',
    label: '拓展信息',
    component: 'Input',
    slot: 'extInfoList',
  },
  {
    field: 'itemCapital',
    label: '合同金额',
    show: false,
    component: 'Input',
    componentProps: {
      disabled: true,
    },
  },
  {
    field: 'contractRequirementList',
    label: '合同特殊要求',
    component: 'Input',
    slot: 'contractRequirementList',
  },
  {
    field: 'businessTotal',
    label: '业务金额',
    component: 'Input',
    componentProps: {
      disabled: true,
    },
    helpMessage: '业务金额=拓展总金额',
  },
  {
    field: 'contractTotal',
    label: '合同总金额',
    component: 'Input',
    componentProps: {
      disabled: true,
    },
    helpMessage: '合同总金额=拓展总金额+专家费',
  },
  {
    field: 'beginDate',
    label: '开始日期',
    component: 'DatePicker',
  },
  {
    field: 'endDate',
    label: '结束日期',
    component: 'DatePicker',
  },
  {
    field: 'serviceType',
    label: '服务方式',
    required: true,
    component: 'Select',
    componentProps: {
      options: [
        {
          label: '按次',
          value: '按次',
          key: '1',
        },
        {
          label: '按月',
          value: '按月',
          key: '2',
        },
        {
          label: '按季',
          value: '按季',
          key: '3',
        },

      ],
    },
  },
  {
    field: 'serviceFrequency',
    label: '服务频次',
    component: 'Input',
  },
  {
    field: 'deliveryAmount',
    label: '派工金额',
    component: 'Input',
  },
  {
    field: 'acceptDept',
    label: '接收人员',
    component: 'ApiSelect',
    componentProps: {
      api: getAllList,
      showSearch: true,       
      optionFilterProp: 'label',
      params: {},
      labelField: 'realName',
      valueField: 'id',
    },
    required: true,
  },
  {
    field: 'confirmFileList',
    label: '收入确认明细表',
    component: 'Upload',
    colProps: { span: 24 },
    componentProps: {
      api: uploadApi,
    },
  },

];
